package com.syqc.choose.teamcar

import androidx.fragment.app.Fragment
import com.gyf.immersionbar.ktx.immersionBar
import com.syqc.adapter.IFragmentPAdapter
import com.syqc.choose.car.HistoryFragment
import com.syqc.choose.car.SearchFragment
import com.syqc.comlib.base.BaseActivity
import com.syqc.comlib.custom.MRadioToolbar
import com.syqc.interfaces.SimplePageChangeListener
import com.syqc.monitor.R
import com.syqc.monitor.databinding.ActivityChooseCarBinding
import com.syqc.monitor.databinding.IncludeToolbarRadioBinding
import com.syqc.monitor.databinding.IncludeViewpagerMatchBinding
import com.syqc.utils.Keys

/**
 *@author joker
 *@time   2024/5/31 11:02
 *@desc
 */
class TeamsCarsActivity : BaseActivity<ActivityChooseCarBinding>(ActivityChooseCarBinding::inflate),
    SimplePageChangeListener {
    private lateinit var mToolBarVB: IncludeToolbarRadioBinding
    private lateinit var mViewPagerVB: IncludeViewpagerMatchBinding
    private val fragments by lazy { mutableListOf<Fragment>() }

    private var isVideo = false
    //是否要切换车队
    private var isChange=false


    override fun initView() {
        mToolBarVB = IncludeToolbarRadioBinding.bind(binding.root)
        mViewPagerVB = IncludeViewpagerMatchBinding.bind(binding.root)
        immersionBar { titleBar(mToolBarVB.mCarRadioBar) }
        isChange = intent.getBooleanExtra("isChange",false)
        isVideo = intent.getBooleanExtra(Keys.INTENT_IS_VIDEO, false)
        initData()
    }

    override fun setListener() {
        mToolBarVB.mCarRadioBar.setTitle(
            R.string.desc_toolbar_car_choose,
            R.string.desc_toolbar_car_search,
            R.string.desc_toolbar_car_history
        )
        mToolBarVB.mCarRadioBar.setCallBack(object : MRadioToolbar.IToolbarCallback {
            override fun startCallback() {
                mViewPagerVB.mViewPager.currentItem = 0
            }

            override fun centerCallback() {
                mViewPagerVB.mViewPager.currentItem = 1
            }

            override fun endCallback() {
                mViewPagerVB.mViewPager.currentItem = 2
            }
        })
    }

    override fun onPageSelected(position: Int) {
        mToolBarVB.mCarRadioBar.setCheck(position)
    }

    private fun initData() {
        val isVideoCar = intent.getBooleanExtra("VideoCar", false)
        fragments.add(CarsFragment(isVideo,isChange ))
        fragments.add(SearchFragment(isVideo,isChange))
        fragments.add(HistoryFragment(isVideo, isVideoCar,isChange))
        mViewPagerVB.mViewPager.adapter = IFragmentPAdapter(supportFragmentManager, fragments)
        mViewPagerVB.mViewPager.offscreenPageLimit = 3
        mViewPagerVB.mViewPager.addOnPageChangeListener(this)
    }
}